﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CashResource;
using CashDriver;
using CashCommon;

namespace Cash.DialogFroms
{
    public partial class FormCashOperation : Form
    {
        public FormCashOperation()
        {
            InitializeComponent();
            this.Text = CommonText.CashOperationFormTitle;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //FrkDrv.Inst.ShowProperties();

            frmProgress = new FrmProgress(CommonText.ProgressFormTitleDriver);
            frmProgress.Show();
            BackgroundWorker bgw = new BackgroundWorker();
            bgw.DoWork += new DoWorkEventHandler(bgw_DoWorkForDriverProperties);
            bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
            bgw.RunWorkerAsync();
        }

        private void FormCashOperation_HelpButtonClicked(object sender, CancelEventArgs e)
        {
            Tools.GetHelp("operation_cash", HelpNavigator.Topic);
            e.Cancel = true;
        }

        /// <summary>
        /// Закрытие смыны с гашением
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDailyReportClose_Click(object sender, EventArgs e)
        {
            frmProgress = new FrmProgress(CommonText.ProgressFormTitleWithClose);
            BackgroundWorker bgw = new BackgroundWorker();
            bgw.DoWork += new DoWorkEventHandler(bgw_DoWorkWithClose);
            bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
            bgw.RunWorkerAsync();
            frmProgress.ShowDialog();
        }

        /// <summary>
        /// Закрытие без гашения
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDailyReportWithoutClose_Click(object sender, EventArgs e)
        {
            frmProgress = new FrmProgress(CommonText.ProgressFormTitleWithClose);
            BackgroundWorker bgw = new BackgroundWorker();
            bgw.DoWork += new DoWorkEventHandler(bgw_DoWorkWithoutClose);
            bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
            bgw.RunWorkerAsync();
            frmProgress.ShowDialog();
        }

        #region Helper

        // Открытие формы настройки драйвера
        private void bgw_DoWorkForDriverProperties(object sender, DoWorkEventArgs e)
        {
            FrkDrv.Inst.ShowProperties();
        }
        // Закрытие смены с гашением
        private void bgw_DoWorkWithClose(object sender, DoWorkEventArgs e)
        {
            FrkDrv.Inst.PrintReportWithCleaning();
        }
        // Закрытие смены без гашения
        private void bgw_DoWorkWithoutClose(object sender, DoWorkEventArgs e)
        {
            FrkDrv.Inst.PrintReportWithoutCleaning();
        }
        // Продолжение печати чека
        private void btnPrintContinue_Click(object sender, EventArgs e)
        {
            FrkDrv.Inst.ContinuePrint();
        }
        // Закрывается диалоговая форма
        private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (frmProgress != null)
                frmProgress.Close();
        }


        #endregion

        private FrmProgress frmProgress;

        private void FormCashOperation_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1)
                FormCashOperation_HelpButtonClicked(null, new CancelEventArgs());
        }

    }
}
